package com.badlogic.androidgames.mrnom.active;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.widget.Toast;

public class Read_Write extends Activity{
	private final static String NOTES="notes.txt";
	
	public boolean readFile(){
		try {
			InputStream in=openFileInput(NOTES);
			
			if (in!=null) {
				InputStreamReader tmp=new InputStreamReader(in);
				BufferedReader reader=new BufferedReader(tmp);
				String str;
				StringBuffer buf=new StringBuffer();
				
				while ((str = reader.readLine()) != null) {
					buf.append(str+"\n");
					return true;//co du lieu trong file
				}
				
				in.close();				
			}
		}
		catch (java.io.FileNotFoundException e) {
			// that's OK, we probably haven't created it yet
		}
		catch (Throwable t) {
			Toast
				.makeText(this, "Exception: "+t.toString(), 2000)
				.show();
		}
		return false;//khong co du lieu trong file
	}
	
	public boolean writeFile() {
		try {
			OutputStreamWriter out=
					new OutputStreamWriter(openFileOutput(NOTES, 0));
			
			out.write("1");
			out.close();		
		}
		catch (Throwable t) {
			Toast
				.makeText(this, "Exception: " + t.toString(), 2000)
				.show();
			return false;//that bai
		}
		return true;//thanh cong
	}

}
